<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
  <title>已办任务</title>
  <div th:replace="common/link::header"></div>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-card">
      <form class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">流程名称</label>
            <div class="layui-input-block">
              <input type="text" name="name" placeholder="请输入流程名称" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <button type="button" class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
            <button type="reset" class="layui-btn layui-btn-primary" lay-submit lay-filter="reset">重置</button>
          </div>
        </div>
      </form>
      <div class="layui-card-body">
        <table id="historicTaskTable" lay-filter="historicTaskTable"></table>
        <script type="text/html" id="tableBar">
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="monitor">审批历史</a>
        </script>
      </div>
    </div>
  </div>
<div th:replace="common/script::footer"></div>
<script th:inline="javascript">
  layui.config({
      base: '/static/layuiadmin/' //静态资源所在路径
  }).extend({
      index: 'lib/index' //主入口模块
  }).use(['index', 'useradmin', 'table'], function() {
    let $ = layui.$,
            form = layui.form,
            table = layui.table;
      //监听搜索
      form.on('submit(search)', function(data) {
        let field = data.field;
          //执行重载
          table.reload('historicTaskTable', {
              where: field
          });
      });
      //监听重置
      form.on('submit(reset)', function(data) {
        Object.keys(data.field).forEach(key => (data.field[key] = ''));
        table.reload('historicTaskTable', {
          where: data.field
        });
      });
      // 查询列表接口
      table.render({
          elem: '#historicTaskTable'
          ,height: 'full-110'
          ,url:  ctx + '/workFlow/historicTask'
          ,cellMinWidth: 80
          ,page: true //开启分页,
          ,cols: [[ //表头
            {field: 'id', title: 'ID', hide:true},
            {field: 'name', title: '流程名称'},
            {field: 'startUser', title: '发起人'},
            {field: 'startTime', title: '开始日期'},
            {field: 'endTime', title: '结束日期'},
            {field: 'businessKey', title: '业务ID'},
            {toolbar: '#tableBar', title: '操作', width: 300, align:'center',fixed: 'right'}
          ]]
      });
      //监听行工具事件
      table.on('tool(historicTaskTable)', function(obj) {
        let data = obj.data //获得当前行数据
                ,layEvent = obj.event;
        if(layEvent === 'monitor'){
          active.monitorView(data.id);
        }
      });
      /* 触发弹层 */
      let active = {
        /**
         * 审批历史
         * @param id 流程实例ID
         */
        monitorView: function (id) {
          layer.open({
            type: 2
            ,shade: 0.3
            ,title: '审批历史'
            ,content: ctx + '/workFlow/monitorPage?processInstanceId=' + id
            ,maxmin: true
            ,scrollbar: false
            ,area: ['100%', '100%']
            ,btn: ['确定']
          });
        }
      }
  });
</script>
</body>
</html>
